#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" @namespace Panel
Game logics on levels


Copyright 2007, NATE-LSI-EPUSP

QCMusical is developed in Brazil at Escola Politécnica of 
Universidade de São Paulo. NATE is part of LSI (Integrable
Systems Laboratory) and stands for Learning, Work and Entertainment
Research Group. Visit our web page: 
www.lsi.usp.br/nate
Suggestions, bugs and doubts, please email nate-lsi@googlegroups.com
or get in http://code.google.com/p/qcmusical/

QCMusical is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation version 2 of 
the License.

QCMusical is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public
License along with Oficina; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 
Boston, MA  02110-1301  USA.
The copy of the GNU General Public License is found in the 
COPYING file included in the source distribution.


Authors:

Pedro Kayatt                        (pekayatt@gmail.com)


Group Manager:
Irene Karaguilla Ficheman           (irene@lsi.usp.br)

Cientific Coordinator:
Roseli de Deus Lopes                (roseli@lsi.usp.br)

"""

import os, sys

#including pygame library
import pygame
from pygame.locals import *

try:
    from sugar.activity.activity import get_bundle_path
except ImportError:
    def get_bundle_path():
        return '.'
##Patch where images are store
images_dir = os.path.join( get_bundle_path(), "imagens" )
##Patch where sounds are store
sounds_dir = os.path.join( get_bundle_path(), "sounds" )


class Panel(object):
    """ This class have the job of create and manipulate the game panel.
        Here we have the pieces of game (sound and image), and the slots spaces.    
    """
    screen = None
    difsel = None
    msg = "Click in one fish to START. "
    #msg = "Clique em um dos peixes para iniciar"
    image = None
    noPiece = 0
    level = 0
    slot = [False,False,False,False,False,False,False,False,False]
    slotPiece = [0,0,0,0,0,0,0,0,0]
    image_p     = [0,0,0,0,0,0,0,0,0]
    sound       = [0,0,0,0,0,0,0,0,0,0,0]
    piece_used   = [False,False,False,False,False,False,False,False,False]
    soundPart = []
    piece_msg = ""

    ##The Constructor
    def __init__(self,level): 
        self.screen      = pygame.display.get_surface()

        for i in range(11):
    	    self.soundPart.append([])
            for j in range(11):
                self.soundPart[i].append(0)

        self.load_midia()

    def load_midia(self):
        """Load all sounds and images needed
        
            @param self     The Panel Object
        """
        def load_image( filename ):
            img = pygame.image.load(filename)
            img.set_alpha( None, RLEACCEL ) # disable alpha.
            img = img.convert()
            img.set_colorkey( ( 255, 0, 255 ), RLEACCEL ) # magenta
            return img
        # load_image()
        
        p  = images_dir + os.path.sep
        self.image_panel  = load_image( p + "panel.png") 
        self.image_places = load_image( p + "vazios.png") 
        self.image_ear    = load_image( p + "ouvido.png")
        self.image_close  = load_image( p + "fechar.png")
        self.image_play   = load_image( p + "play.png")
        self.image_hide   = load_image( p + "esconde_vazio.png") 
        self.piece_empty  = load_image( p + "pecas/" + "p0.png")
        #pieces
        self.image_p[1] = load_image( p + "pecas/" + "p1.png") 
        self.image_p[2] = load_image( p + "pecas/" + "p2.png")           
        self.image_p[3] = load_image( p + "pecas/" + "p3.png") 
        self.image_p[4] = load_image( p + "pecas/" + "p4.png") 
        self.image_p[5] = load_image( p + "pecas/" + "p5.png") 
        self.image_p[6] = load_image( p + "pecas/" + "p6.png") 
        self.image_p[7] = load_image( p + "pecas/" + "p7.png") 
        self.image_p[8] = load_image( p + "pecas/" + "p8.png") 

        #musicas
        s = sounds_dir + os.path.sep
        self.sound[1] =  s + "DancaHungara.ogg"
        self.sound[2] =  s + "MorningMood.ogg"
        self.sound[3] =  s + "AssimfalavaZaratustra.ogg"
        self.sound[4] =  s + "IlCatalogoEhQuesto.ogg"
        self.sound[5] =  s + "Cantilena.ogg"
        #self.sound[6] =  s + "Brasileirinho.ogg"
        
        self.sound[7] =  s + "HallOfTheMountainKing.ogg"
        self.sound[8] =  s + "YoureTheWeaverOfDreams.ogg"
        self.sound[9] =  s + "BoleroDeRavel.ogg"
        #self.sound[10] = s + "PelaInternet.ogg"
        #pieces of musics!
        self.soundPart[1][1] = s + "dhg/" + "DancaHungaraParte2.ogg"#lvl1
        self.soundPart[1][2] = s + "dhg/" + "DancaHungaraParte1.ogg"
        self.soundPart[1][3] = s + "dhg/" + "DancaHungaraParte3.ogg"
        self.soundPart[1][4] = s + "dhg/" + "DancaHungaraParte4.ogg"
        self.soundPart[2][1] = s + "mrm/" + "MorningMoodParte3.ogg"#lvl2
        self.soundPart[2][2] = s + "mrm/" + "MorningMoodParte2.ogg"
        self.soundPart[2][3] = s + "mrm/" + "MorningMoodParte1.ogg"
        self.soundPart[2][4] = s + "mrm/" + "MorningMoodParte4.ogg"
        self.soundPart[3][1] = s + "afz/" + "AssimfalavaZaratustraParte4.ogg"#lvl3
        self.soundPart[3][2] = s + "afz/" + "AssimfalavaZaratustraParte2.ogg"
        self.soundPart[3][3] = s + "afz/" + "AssimfalavaZaratustraParte3.ogg"
        self.soundPart[3][4] = s + "afz/" + "AssimfalavaZaratustraParte1.ogg"
        self.soundPart[4][1] = s + "icq/" + "IlcatalogoequestoParte4.ogg"#lvl4
        self.soundPart[4][2] = s + "icq/" + "IlcatalogoequestoParte3.ogg"
        self.soundPart[4][3] = s + "icq/" + "IlcatalogoequestoParte2.ogg"
        self.soundPart[4][4] = s + "icq/" + "IlcatalogoequestoParte1.ogg"
        self.soundPart[5][1] = s + "cnt/" + "CantilenaParte1.ogg"#lvl5
        self.soundPart[5][2] = s + "cnt/" + "CantilenaParte3.ogg"
        self.soundPart[5][3] = s + "cnt/" + "CantilenaParte4.ogg"
        self.soundPart[5][4] = s + "cnt/" + "CantilenaParte2.ogg"
        """self.soundPart[6][1] = s + "hfm/" + "CantilenaParte4.ogg"#lvl6
        self.soundPart[6][2] = s + "hfm/" + "CantilenaParte4.ogg"
        self.soundPart[6][3] = s + "hfm/" + "CantilenaParte4.ogg"
        self.soundPart[6][4] = s + "hfm/" + "CantilenaParte4.ogg"""

        self.soundPart[7][1] = s + "hfm/" + "HallofthemountainkingParte4.ogg"#lvl7
        self.soundPart[7][2] = s + "hfm/" + "HallofthemountainkingParte1.ogg"
        self.soundPart[7][3] = s + "hfm/" + "HallofthemountainkingParte2.ogg"
        self.soundPart[7][4] = s + "hfm/" + "HallofthemountainkingParte8.ogg"
        self.soundPart[7][5] = s + "hfm/" + "HallofthemountainkingParte5.ogg"
        self.soundPart[7][6] = s + "hfm/" + "HallofthemountainkingParte3.ogg"
        self.soundPart[7][7] = s + "hfm/" + "HallofthemountainkingParte6.ogg"
        self.soundPart[7][8] = s + "hfm/" + "HallofthemountainkingParte7.ogg"
        self.soundPart[8][1] = s + "ywd/" + "YouretheweaverofdreamsParte8.ogg"#lvl8
        self.soundPart[8][2] = s + "ywd/" + "YouretheweaverofdreamsParte5.ogg"
        self.soundPart[8][3] = s + "ywd/" + "YouretheweaverofdreamsParte3.ogg"
        self.soundPart[8][4] = s + "ywd/" + "YouretheweaverofdreamsParte2.ogg"
        self.soundPart[8][5] = s + "ywd/" + "YouretheweaverofdreamsParte6.ogg"
        self.soundPart[8][6] = s + "ywd/" + "YouretheweaverofdreamsParte1.ogg"
        self.soundPart[8][7] = s + "ywd/" + "YouretheweaverofdreamsParte4.ogg"
        self.soundPart[8][8] = s + "ywd/" + "YouretheweaverofdreamsParte7.ogg"
        self.soundPart[9][1] = s + "bdr/" + "BoleroParte5.ogg"#lvl9
        self.soundPart[9][2] = s + "bdr/" + "BoleroParte6.ogg"
        self.soundPart[9][3] = s + "bdr/" + "BoleroParte1.ogg"
        self.soundPart[9][4] = s + "bdr/" + "BoleroParte3.ogg"
        self.soundPart[9][5] = s + "bdr/" + "BoleroParte4.ogg"
        self.soundPart[9][6] = s + "bdr/" + "BoleroParte8.ogg"
        self.soundPart[9][7] = s + "bdr/" + "BoleroParte7.ogg"
        self.soundPart[9][8] = s + "bdr/" + "BoleroParte2.ogg"
        """self.soundPart[10][1]= s + "cnt/" + "CantilenaParte4.ogg"#lvl10
        self.soundPart[10][2]= s + "cnt/" + "CantilenaParte4.ogg"
        self.soundPart[10][3]= s + "cnt/" + "CantilenaParte4.ogg"
        self.soundPart[10][4]= s + "cnt/" + "CantilenaParte4.ogg"
        self.soundPart[10][5]= s + "cnt/" + "CantilenaParte4.ogg"
        self.soundPart[10][6]= s + "cnt/" + "CantilenaParte4.ogg"
        self.soundPart[10][7]= s + "cnt/" + "CantilenaParte4.ogg"        
        self.soundPart[10][8]= s + "cnt/" + "CantilenaParte4.ogg"""

    def start_level(self):
        """When a level is started restart the configurations of the Panel
            @param self     The Panel Object
        """
    
        self.image==None
        self.noPiece=0
        self.slot = [False,False,False,False,False,False,False,False,False]
        self.slotPiece = [0,0,0,0,0,0,0,0,0]
        self.piece_used   = [False,False,False,False,False,False,False,False,False]
        
    
    def draw(self, screen, difsel, level): 
        """This function draw every image when a panel is opened, including the pieces
    
            @param self     The Panel Object
            @param screen   screen from QCMusical Object
            @param difsel   which difficult is selected
            @param level    which level is selected
    
        """

        screen.blit(self.image_panel, (0,601))
        screen.blit(self.image_places, (440,675))
        screen.blit(self.image_ear, (1110, 630))
        screen.blit(self.image_play, (908,692))
        screen.blit(self.image_close, (5,605))
        
        font = pygame.font.Font(None, 24)
        instrution = font.render("Drag and Drop the pieces in order below." , True, [0,0,0])
        verify = font.render("Verify", True, [0,0,0])
        tip = font.render("Tip", True, [0,0,0])
        
        self.screen.blit(instrution, (445,650))
        self.screen.blit(verify, (925,700))
        self.screen.blit(tip, (1070,635))
        
       
        if (self.image!=self.image_p[1]) & (self.noPiece!=1): 
            self.piece_used[1] = False
            screen.blit(self.image_p[1], (100, 645) )
        if (self.image!=self.image_p[2]) & (self.noPiece!=2):
            self.piece_used[1] = False
            screen.blit(self.image_p[2], (170, 645) )
        if (self.image!=self.image_p[3]) & (self.noPiece!=3):
            self.piece_used[1] = False
            screen.blit(self.image_p[3], (240, 645) )
        if (self.image!=self.image_p[4]) & (self.noPiece!=4):
            self.piece_used[1] = False
            screen.blit(self.image_p[4], (310, 645) )
        
        for i in range(9) :
            if (self.slotPiece[i]==1) or (self.noPiece==1):  
                self.piece_used[1] = True
                screen.blit(self.piece_empty, (100, 645) )
            if (self.slotPiece[i]==2) or (self.noPiece==2):   
                self.piece_used[2] = True            
                screen.blit(self.piece_empty, (170, 645) )
            if (self.slotPiece[i]==3) or (self.noPiece==3):    
                self.piece_used[3] = True           
                screen.blit(self.piece_empty, (240, 645) )
            if (self.slotPiece[i]==4) or (self.noPiece==4):    
                self.piece_used[4] = True           
                screen.blit(self.piece_empty, (310, 645) )

        #to hide slot places on easy
        if difsel==0:
            screen.blit(self.image_hide, (669, 675) )
            screen.blit(self.image_hide, (724, 675) )
            screen.blit(self.image_hide, (780, 675) )
            screen.blit(self.image_hide, (836, 675) )
        elif difsel==1:
            if (self.image!=self.image_p[5]) and (self.noPiece!=5):
                screen.blit(self.image_p[5], (100, 710) )
            if (self.image!=self.image_p[6]) and (self.noPiece!=6):
                screen.blit(self.image_p[6], (170, 710) )
            if (self.image!=self.image_p[7]) and (self.noPiece!=7):        
                screen.blit(self.image_p[7], (240, 710) )
            if (self.image!=self.image_p[8]) and (self.noPiece!=8):             
                screen.blit(self.image_p[8], (310, 710) )
                
            for i in range(9):                
                if (self.slotPiece[i]==5) or (self.noPiece==5):               
                    screen.blit(self.piece_empty, (100, 710) )
                if (self.slotPiece[i]==6) or (self.noPiece==6):               
                    screen.blit(self.piece_empty, (170, 710) )
                if (self.slotPiece[i]==7) or (self.noPiece==7):               
                    screen.blit(self.piece_empty, (240, 710) )
                if (self.slotPiece[i]==8) or (self.noPiece==8):               
                    screen.blit(self.piece_empty, (310, 710) )

        if (self.slot[1]==True) and self.slotPiece[1]!=0:
                self.screen.blit(self.image_p[self.slotPiece[1]], (443, 675) )
        if (self.slot[2]==True) and self.slotPiece[2]!=0:
                self.screen.blit(self.image_p[self.slotPiece[2]], (500, 675) )
        if (self.slot[3]==True) and self.slotPiece[3]!=0:
                self.screen.blit(self.image_p[self.slotPiece[3]], (555, 675) )
        if (self.slot[4]==True) and self.slotPiece[4]!=0:
                self.screen.blit(self.image_p[self.slotPiece[4]], (610, 675) )
        if (self.slot[5]==True) and self.slotPiece[5]!=0:
                self.screen.blit(self.image_p[self.slotPiece[5]], (665, 675) )
        if (self.slot[6]==True) and self.slotPiece[6]!=0:
                self.screen.blit(self.image_p[self.slotPiece[6]], (720, 675) )
        if (self.slot[7]==True) and self.slotPiece[7]!=0:
                self.screen.blit(self.image_p[self.slotPiece[7]], (775, 675) )
        if (self.slot[8]==True) and self.slotPiece[8]!=0:
                self.screen.blit(self.image_p[self.slotPiece[8]], (830, 675) )

        self.pieceMsg()
        
        if (self.image!=None):
            screen.blit(self.image, pygame.mouse.get_pos() )
  
    def playSong(self,level):
        """ Play the entire song of level
    
            @param self     The Panel Object
            @param level    The level who needs the Song play
        """

        if (level!=0):
            pygame.mixer.music.load(self.sound[level])
            pygame.mixer.music.play()
           # while pygame.mixer.music.get_busy(): #to wait entire music
           #     pygame.event.wait()
            
      
    
    def playPart(self, noPiece):
        """ Just play the part of Song correlated with the piece that you just clicked
        
            @param self     The Panel Object
            @param noPiece  Which piece needs be played
        """
        pygame.mixer.music.load(self.soundPart[self.level][noPiece])
        pygame.mixer.music.play()
        

    def statusMsg(self, msg=""):
        """ Draw and mesage on STATUS BAR
    
            @param self     The Panel Object
            @param msg      Mesage who will be draw
        """
        msg=self.msg
        font = pygame.font.Font(None, 24)
        saying = font.render(msg, True, [0,0,0])
        self.screen.blit(saying, (5,805))
    
    def pieceMsg(self, msg=""):
        """ This function print a message of which piece is not in the right place
    
            @param self     The Panel Object
            @param msg      Mesage who will be draw
        
        """
        msg=self.piece_msg
        font = pygame.font.Font(None, 24)
        saying = font.render(msg, True, [0,0,0])
        self.screen.blit(saying, (450,735))

    def events(self,event,key,pos):
        """ Handle with evens of mouse or keyboard
        
            @param self     The Panel Object
            @param event    Events who need be handle
            @param key      Key which is pressed
            @param pos      Coordenates of where is the cursor
        
        """
          
        if (event==MOUSEBUTTONDOWN):
            if (100<pos[0]<160) and (645<pos[1]<695) :
                if not self.piece_used[1]:
                    self.image=self.image_p[1]
                    self.noPiece=1
                    self.playPart(self.noPiece)
                    self.piece_used = [False,True,False,False,False,False,False,False,False]
                    for i in range(9) :
                        if (self.slotPiece[i]==self.noPiece):               
                            self.slot[i]=False
                else:
                    self.image=None
                    self.noPiece=0
                    self.piece_used[1] = False
                    
            elif (170<pos[0]<230) and (645<pos[1]<695):
                if not self.piece_used[2]:
                    self.image=self.image_p[2]
                    self.noPiece=2
                    self.playPart(self.noPiece)
                    self.piece_used = [False,False,True,False,False,False,False,False,False]
                    for i in range(9) :               
                        if (self.slotPiece[i]==self.noPiece):               
                            self.slot[i]=False
                else:
                    self.image=None
                    self.noPiece=0
                    self.piece_used[2] = False
                    
            elif (240<pos[0]<300) and (645<pos[1]<695):
                if not self.piece_used[3]:
                    self.image=self.image_p[3]
                    self.noPiece=3
                    self.playPart(self.noPiece)
                    self.piece_used = [False,False,False,True,False,False,False,False,False]
                    for i in range(9) :               
                        if (self.slotPiece[i]==self.noPiece):               
                            self.slot[i]=False
                else:
                    self.image=None
                    self.noPiece=0
                    self.piece_used[3] = False
                    
            elif (310<pos[0]<370) and (645<pos[1]<695):
                if not self.piece_used[4]:
                    self.image=self.image_p[4]
                    self.noPiece=4
                    self.playPart(self.noPiece)
                    self.piece_used = [False,False,False,False,True,False,False,False,False]
                    for i in range(9) :               
                        if (self.slotPiece[i]==self.noPiece):               
                            self.slot[i]=False
                else:
                    self.image=None
                    self.noPiece=0
                    self.piece_used[4] = False
                        
            if (self.difsel==1):         
                if (100<pos[0]<160) and (715<pos[1]<765):
                    if not self.piece_used[5]:
                        self.image=self.image_p[5]
                        self.noPiece=5
                        self.playPart(self.noPiece)
                        self.piece_used = [False,False,False,False,False,True,False,False,False]
                        for i in range(9) :               
                            if (self.slotPiece[i]==self.noPiece):               
                                self.slot[i]=False
                    else:
                        self.image=None
                        self.noPiece=0      
                        self.piece_used[5] = False      
                elif (170<pos[0]<230) and (715<pos[1]<765):
                    if not self.piece_used[6]:
                        self.image=self.image_p[6]
                        self.noPiece=6
                        self.playPart(self.noPiece)
                        self.piece_used = [False,False,False,False,False,False,True,False,False]
                        for i in range(9) :               
                            if (self.slotPiece[i]==self.noPiece):               
                                self.slot[i]=False
                    else:
                        self.image=None
                        self.noPiece=0
                        self.piece_used[6] = False
                elif (240<pos[0]<300) and (715<pos[1]<765):
                    if not self.piece_used[7]:
                        self.image=self.image_p[7]
                        self.noPiece=7
                        self.playPart(self.noPiece)
                        self.piece_used = [False,False,False,False,False,False,False,True,False]
                        for i in range(9) :               
                            if (self.slotPiece[i]==self.noPiece):               
                                    self.slot[i]=False
                    else:
                        self.image=None
                        self.noPiece=0   
                        self.piece_used[7] = False
                elif (300<pos[0]<370) and (715<pos[1]<765):
                    if not self.piece_used[8]:
                        self.image=self.image_p[8]
                        self.noPiece=8
                        self.playPart(self.noPiece)
                        self.piece_used = [False,False,False,False,False,False,False,False,True]
                        for i in range(9) :               
                            if (self.slotPiece[i]==self.noPiece):               
                                self.slot[i]=False
                    else:
                        self.image=None
                        self.noPiece=0   
                        self.piece_used[8] = False
                              
            #handle with piece slots places
            if (440<pos[0]<500) and (675<pos[1]<730):
                if self.slot[1]:
                    tempPiece = self.noPiece
                    self.noPiece = self.slotPiece[1]
                    self.playPart(self.noPiece)
                    if self.image!=None :
                        self.slot[1]=True
                        self.slotPiece[1] = tempPiece
                    else :
                        self.slot[1]=False
                        self.slotPiece[1]=0
                    self.image=self.image_p[self.noPiece]
                elif self.image!=None :
                    self.slot[1]=True
                    self.slotPiece[1]=self.noPiece
                    self.image=None
                        
            if (500<pos[0]<555) and (675<pos[1]<730):
                if self.slot[2]:
                    tempPiece = self.noPiece
                    self.noPiece = self.slotPiece[2]
                    self.playPart(self.noPiece)
                    if self.image!=None :
                        self.slot[2]=True
                        self.slotPiece[2] = tempPiece
                    else :
                        self.slot[2]=False
                        self.slotPiece[2]=0
                    self.image=self.image_p[self.noPiece]
                elif self.image!=None :
                    self.slot[2]=True
                    self.slotPiece[2]=self.noPiece
                    self.image=None
            
            if (560<pos[0]<610) and (675<pos[1]<730):
                if self.slot[3]:
                    tempPiece = self.noPiece
                    self.noPiece = self.slotPiece[3]
                    self.playPart(self.noPiece)
                    if self.image!=None :
                        self.slot[3]=True
                        self.slotPiece[3] = tempPiece
                    else :
                        self.slot[3]=False
                        self.slotPiece[3]=0
                    self.image=self.image_p[self.noPiece]
                elif self.image!=None :
                    self.slot[3]=True
                    self.slotPiece[3]=self.noPiece
                    self.image=None
             
            if (610<pos[0]<665) and (675<pos[1]<730):
                if self.slot[4]:
                    tempPiece = self.noPiece
                    self.noPiece = self.slotPiece[4]
                    self.playPart(self.noPiece)
                    if self.image!=None :
                        self.slot[4]=True
                        self.slotPiece[4] = tempPiece
                    else :
                        self.slot[4]=False
                        self.slotPiece[4]=0
                    self.image=self.image_p[self.noPiece]
                elif self.image!=None :
                    self.slot[4]=True
                    self.slotPiece[4]=self.noPiece
                    self.image=None
                              
            if (self.difsel==1):
                if (665<pos[0]<725) and (675<pos[1]<730):
                    if self.slot[5]:
                        tempPiece = self.noPiece
                        self.noPiece = self.slotPiece[5]
                        self.playPart(self.noPiece)
                        if self.image!=None :
                            self.slot[5]=True
                            self.slotPiece[5] = tempPiece
                        else :
                            self.slot[5]=False
                            self.slotPiece[5]=0
                        self.image=self.image_p[self.noPiece]
                    elif self.image!=None :
                        self.slot[5]=True
                        self.slotPiece[5]=self.noPiece
                        self.image=None
                        
                if (725<pos[0]<775) and (675<pos[1]<730):
                    if self.slot[6]:
                        tempPiece = self.noPiece
                        self.noPiece = self.slotPiece[6]
                        self.playPart(self.noPiece)
                        if self.image!=None :
                            self.slot[6]=True
                            self.slotPiece[6] = tempPiece
                        else :
                            self.slot[6]=False
                            self.slotPiece[6]=0
                        self.image=self.image_p[self.noPiece]
                    elif self.image!=None :
                        self.slot[6]=True
                        self.slotPiece[6]=self.noPiece
                        self.image=None
                            
                if (775<pos[0]<830) and (675<pos[1]<730):
                    if self.slot[7]:
                        tempPiece = self.noPiece
                        self.noPiece = self.slotPiece[7]
                        self.playPart(self.noPiece)
                        if self.image!=None :
                            self.slot[7]=True
                            self.slotPiece[7] = tempPiece
                        else :
                            self.slot[7]=False
                            self.slotPiece[7]=0
                        self.image=self.image_p[self.noPiece]
                    elif self.image!=None :
                        self.slot[7]=True
                        self.slotPiece[7]=self.noPiece
                        self.image=None
                        
                if (830<pos[0]<885) and (675<pos[1]<730):
                    if self.slot[8]:
                        tempPiece = self.noPiece
                        self.noPiece = self.slotPiece[8]
                        self.playPart(self.noPiece)
                        if self.image!=None :
                            self.slot[8]=True
                            self.slotPiece[8] = tempPiece
                        else :
                            self.slot[8]=False
                            self.slotPiece[8]=0
                        self.image=self.image_p[self.noPiece]
                    elif self.image!=None :
                        self.slot[8]=True
                        self.slotPiece[8]=self.noPiece
                        self.image=None
